package com.zizy.healthexpert.Adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.zizy.healthexpert.R;

import java.util.List;
import android.view.View;

/**
 * Created by Zizy on 2014/6/28.
 *
 *
 * this adapter is for addResultActivity to show the added foods.
 */
public class listAddedDishesAdapter extends ArrayAdapter {
    private Context context=null;
    private int res=0;

    public listAddedDishesAdapter (Context context, int resource, List objects) {
        super(context, resource, objects);
        this.context=context;
        this.res=resource;
    }
    @Override
     public View getView(final int position, View convertView, ViewGroup parent) {
        //TODO
        ViewGroup viewGroup = (ViewGroup) View.inflate(context, res, null);//inflate
        addedDishes item=(addedDishes) getItem(position);
        //getView
        TextView txtAddedFoodName=(TextView)viewGroup.findViewById(R.id.txtAddedFoodName);
        Button btnDeleteAddFoods=(Button ) viewGroup.findViewById(R.id.btnDeleteAddedFood);
        //setView
        txtAddedFoodName.setText(item.dishesName);
        btnDeleteAddFoods.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listAddedDishesAdapter.this.remove(getItem(position));
            }
        });
        return viewGroup;
    }
    //a class defined a type 'addedDishes' to describe the food.
    static  public class addedDishes{
        public String dishesName=null; //dishes name
        public  int dishesId=0;         //dishes id in the database or will be 0 if the food is get from QR- Code
        public String  formattedNutrition=null; // a String to describe a the nutrition. exp:1,22;2,0.02;  means the food has  22g nutrition which id is 1;
        /* formattedNutrition:
        *   1,23;2,0.23;
        *
        *
        * */

        public addedDishes(String dishesName, int dishesId, String formattedNutrition) {
            this.dishesName = dishesName;
            this.dishesId = dishesId;
            this.formattedNutrition = formattedNutrition;//1,333;2,3333;
        }
    }




}
